﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.huawei.esdk.tp.oa.DataType;
using System.Web.Services.Protocols;
using com.huawei.esdk.tp.oa.Utils;
using com.huawei.esdk.tp.oa.eSDKTPOAPlatformKeyMgrService;

namespace com.huawei.esdk.tp.oa.local
{
    public partial class PlatformKeyServiceProvider
    {
        private static PlatformKeyMgrService platformKey;

        private static PlatformKeyServiceProvider instance = null;
        protected PlatformKeyServiceProvider()
        {

        }

        public static PlatformKeyServiceProvider Instance(string url)
        {
            if (null == instance)
            {
                instance = new PlatformKeyServiceProvider();
                
            }
            platformKey = new PlatformKeyMgrService(url);
            return instance;
        }

        public TPOASDKResponse<string> getPublicKey()
        {
            TPOASDKResponse<string> resp = new TPOASDKResponse<string>();
            try
            {
                string publicKey = string.Empty;
                resp.resultCode = platformKey.getPublicKey(out publicKey);
                if (resp.resultCode == 0)
                    resp.result = publicKey;
                return resp;
            }
            catch (SoapHeaderException e)
            {
                resp.resultCode = ExceptionUtils.processSoapException(e);
                return resp;
            }
        }
    }
}
